package mcommand;

import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;

/**
 * StringPrinter is a small string utility to draw strings
 * centered on the screen
 * call setScreenWidth() before first use
 * @author Marcel, Chris, Klaus
 *
 */
public class StringPrinter {
    
    private static int screenWidth = 0;
    
    /**
     * sets the screenWidth used by printCentered()
     */
    public static void setScreenWidth(int scrWidth) {
        screenWidth = scrWidth;
    }
    
    /**
     * Prints String at horizontal centered x and profided y-position
     * @param g2d g2d object of parent swing window
     * @param message the message to print on the display
     * @param y y-position of message
     */
    public static void drawStringCentered(Graphics2D g2d, String message, int y) {
        Rectangle2D bounds = g2d.getFontMetrics().getStringBounds(message, g2d);
        int x = (int)(((screenWidth / 2) - (bounds.getWidth()) / 2));
        g2d.drawString(message, x, y);
    }
}
